package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author syh
 * @create 2023-08-16 19:21
 */
@Tag(name = "用户管理模块")
@RestController
@RequestMapping("/admin/system/user")
public class SysUserController {
    @Resource
    SysUserService sysUserService;

    @Operation(summary = "删除")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        sysUserService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "新增")
    @PostMapping
    public Result save(@RequestBody SysUser sysUser){
        sysUserService.save(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据id查询")
    @GetMapping("{id}")
    public Result<SysUser> getById(@PathVariable("id")Long id){
        SysUser sysUser=sysUserService.getById(id);
        return Result.build(sysUser,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "更新")
    @PutMapping
    public Result updateById(@RequestBody SysUser sysUser){
        sysUserService.updateById(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }




    @Operation(summary = "条件查询用户分页数据")
    @GetMapping("page/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> page(@PathVariable("pageNum") Integer pageNum,
                                          @PathVariable("pageSize") Integer pageSize,
                                          SysUserDto sysUserDto){
       PageInfo<SysUser> pageInfo= sysUserService.page(pageNum,pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

}
